home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7306 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: news.cs.su.oz.au!metro!metro!extro!rblayney
  2. From: rblayney@extro.ucc.su.OZ.AU (Robert Blayney)
  3. Newsgroups: comp.lang.c
  4. Subject: newbie question concerning fread
  5. Date: 18 Feb 96 11:41:09 GMT
  6. Organization: Information Services, The University of Sydney, NSW, Australia
  7. Distribution: inet
  8. Message-ID: <rblayney.824643669@extro>
  9. NNTP-Posting-Host: extro.ucc.su.oz.au
  10. Summary: How to use the DATA array passed by fread
  11.  
  12.  
  13. Hi,
  14.     I'm attempting to use the following function call
  15.         fread(&result, sizeof(int), 16, fp);
  16.     Unfortunately when I attempt to print the contents of the result array
  17. I obtain all zeros, where  result is declared:  int *result. I've tried successfully
  18. to use fgets which works on text files but really need to use fread. I'm not sure 
  19. where the problem lies but when I've been printing the result array I've 
  20. been using printf("%-6.2d", *(result + i));
  21.     If anyone could offer me some advice about what I'm doing wrong I'd
  22. appreciate it. 
  23.  
  24. Extract:
  25.      fseek(fp, 0L, SEEK_SET);
  26.        bytesRead = fread(&result, sizeof (int), 16, fp);
  27.              
  28.        for (i = 0; i < bytesRead; i++) {
  29.        printf("%-6.2d", *(result + i));
  30.        }
  31.  
  32. Many Thanks
  33. Rob
  34. (rblayney@extro.ucc.su.oz.au)
  35.